package com.hxht.storage.server.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hxht.storage.server.bean.CurrentRecordingBean;
import com.hxht.storage.server.bean.RecordMarkBean;
import com.hxht.storage.server.bean.RecordSearchBean;
import com.hxht.storage.server.bean.RecordSearchResultBean;
import com.hxht.storage.server.service.RecordSearchService;


@Controller
@RequestMapping("/search")// /{deviceId}/{channelIndex}")
public class RecordSearchController {

	@Autowired
	private RecordSearchService searchService;
	
	@RequestMapping(value = "/", method = RequestMethod.POST)
	@ResponseBody
	public List<RecordSearchResultBean> startSearch(@RequestBody RecordSearchBean searchBean){
		List<RecordSearchResultBean> resultList = searchService.searchRecordByDevice(searchBean);
		
//		System.out.println(JSONObject.toJSONString(resultList));
		return resultList;
	}
	
	/**
	 * 查勤用 搜索接口
	 * @param mark 查勤ID
	 * @return
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	@ResponseBody
	public List<RecordSearchResultBean> startDutyCheckSearch(String mark){
		
		List<RecordSearchResultBean> resultList = searchService.searchManualRecordByMark(mark);
		
		return resultList;
	}
	
	@RequestMapping(value="/mark", method = RequestMethod.POST)
	@ResponseBody
	public Boolean addRecordMark(@RequestBody RecordMarkBean recordMarkBean){
		
		return searchService.addRecordMark(recordMarkBean);
		
	}
	
	@RequestMapping(value="/mark", method = RequestMethod.PUT)
	@ResponseBody
	public void updateRecordMark(String uuid, String content){
		
		searchService.updateRecordMark(uuid, content);
		
	}
	
	@RequestMapping(value="/mark", method = RequestMethod.DELETE)
	@ResponseBody
	public void delRecordMark(String uuid){
		searchService.delRecordMark(uuid);
	}

	@RequestMapping(value="/recording", method = RequestMethod.GET)
	@ResponseBody
	public List<CurrentRecordingBean> getCurrentRecording(){
		
		List<CurrentRecordingBean> recordingList = searchService.getCurrentRecording();
				
		return recordingList;
	}
	
}
